package com.sxkj.web.controller.member;

import com.sxkj.common.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.sxkj.entity.entity.member.Member;
import com.sxkj.service.member.MemberService;

/**
 * @author daixiaowei
 *
 * @description: 会员
 * @date 2019-12-26 17:22:17
 */
@RestController
@RequestMapping("/member/member")
public class MemberController {

	@Autowired
	private MemberService memberService;

	@ApiOperation(value = "根据主键查会员信息")
	@GetMapping(value = "/get/{id}")
	public ResponseResult get(@PathVariable String id) {
		try {
			Member member = memberService.get(id);
			return ResponseResult.success(member);
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "新增会员信息")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ResponseResult save(@RequestBody Member member) {
		try {
			memberService.save(member);
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "删除会员信息")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public ResponseResult delete(@RequestBody Member member) {
		try {
			memberService.delete(member);
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "查询会员列表")
	@RequestMapping(value = "/findList", method = RequestMethod.POST)
	public ResponseResult findList(@RequestBody Member member) {
		try {
			return ResponseResult.success(memberService.findList(member));
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "查询会员列表")
	@RequestMapping(value = "/findPage", method = RequestMethod.POST)
	public ResponseResult findPage(@RequestBody Member member,
			@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		try {
			PageInfo pageInfo = memberService.findPage(member, pageSize, pageNum);
			return ResponseResult.success(pageInfo);
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

}
